package com.hkts.sinoiov.sinoiovRecord.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.sinoiov.utils.CustomPageUtils;
import com.hkts.sinoiov.utils.ResultOpen;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.sinoiov.sinoiovRecord.service.ISinoiovRecordService;
import com.hkts.sinoiov.sinoiovRecord.entity.SinoiovRecord;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author hml
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/sinoiov/sinoiovRecord")
public class SinoiovRecordController {
    private final Logger logger = LoggerFactory.getLogger(SinoiovRecordController.class);

    @Autowired
    public ISinoiovRecordService iSinoiovRecordService;

    /**
     * 分页查询数据
     *
     * @param page          分页信息
     * @param sinoiovRecord 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getSinoiovRecordPageList")
    public Result<Object> getHontUserList(Page<SinoiovRecord> page, SinoiovRecord sinoiovRecord) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iSinoiovRecordService.selectPage(page, sinoiovRecord)));
    }

    /**
     * 保存和修改公用的
     *
     * @param sinoiovRecord 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/sinoiovRecordSave")
    public Result<Object> sinoiovRecordSave(SinoiovRecord sinoiovRecord) {
        iSinoiovRecordService.saveOrUpdate(sinoiovRecord);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/sinoiovRecordGetById")
    public Result<Object> sinoiovRecordGetById(String id) {
        SinoiovRecord byId = iSinoiovRecordService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/sinoiovRecordDelete")
    public Result<Object> hontUserDelete(String id) {
        iSinoiovRecordService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/sinoiovRecordBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iSinoiovRecordService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 获取当前位置信息
     * @param vclN
     */
    @GetMapping("/vLastLocationV3")
    public Result<Object> vLastLocationV3 (String vclN){
        return iSinoiovRecordService.vLastLocationV3(vclN);
    }
    /**
     *  车辆轨迹查询（车牌号）接口
     * @param vclNs
     */
    @GetMapping("/vHisTrack24")
    public Result<Object> vHisTrack24 (@RequestParam String vclNs, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime qryBtm, @RequestParam long hours){
        return iSinoiovRecordService.vHisTrack24( vclNs,qryBtm,hours);
    }

}
